#include <Square.h> 
#include <RectCalc.h>
#include <Range.h>
#include <Precision.h>

namespace
{
#define MIN_VALUE 0
#define MAX_SIDE_VALUE 75

LopenRopenRange sideRange(MIN_VALUE, MAX_SIDE_VALUE);

}

Range* Square::sideRange_m = &sideRange;

//###########################################################
//############# FUNCTION ###################################

Square::Square(const double side_i):
    side_m(Precision::cut(side_i))
{
}


bool Square::isValid() const
{
    return sideRange_m->isValid(side_m);
}

double Square::calcArea() const
{
    double area = RectCalc::calcArea(side_m,side_m);
    return (isValid() ?  Precision::round(area) : 0);
}

double Square::calcPerimeter() const
{
    double perimeter = RectCalc::calcPerimeter(side_m, side_m);
    return (isValid() ? Precision::round(perimeter) : 0);
}


void Square::setSide(const double side_i)
{
    double temp = Precision::cut(side_i);
    if (sideRange_m->isValid(temp))
        side_m = temp;
}



